package servlet;

import dao.GoodsDao;
import dao.TypeDao;
import entity.Goods;
import entity.Type;
import entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/goodsinfo")
public class GoodsInfoServlet extends HttpServlet {
	
	@Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) 
            throws ServletException, IOException {
        doGet(request, response);
    }
	@Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) 
            throws ServletException, IOException {
		System.out.println("------------goodsList-------------");
		User user = (User) request.getSession().getAttribute("user");
		if(user != null){
			Integer goodsId = Integer.valueOf(request.getParameter("goodId"));
			GoodsDao dao = new GoodsDao();
			Goods good = dao.selectGoodByID(goodsId);
			request.setAttribute("selectGood", good);
		}else {
			request.getSession().setAttribute("errorMsg", "请先登录！");
			response.sendRedirect("./frontend/index.jsp");
			return;
		}
		request.getRequestDispatcher("./frontend/goodsinfo.jsp").forward(request, response);
	}


}
